﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Web;

/// <summary>
/// Summary description for bzYahoo
/// </summary>
public class bzYahoo
{
	 private dbConnection _DB = null;
    private string _TableName = "bzYahoo";
    private string _IDType = "_NVARCHAR";
    private string _IDCol = "YahooID";
    private string _IDColParent = "";
    private string _TableChild = "";
    public bzYahoo()
	{
        _DB = new dbConnection();
	}
    public DataTable getTable(string Key,string Enabled,string Page,string Limit)
    {       
        SqlParameter[] p = new SqlParameter[4];
        p[0] = new SqlParameter("@Key", "%"+Key+"%");
        p[1] = new SqlParameter("@Enabled",  Enabled );       
        p[2] = new SqlParameter("@Page", Page);
        p[3] = new SqlParameter("@Limit", Limit);
         return _DB.getDataTable(_TableName+"_search",p);
       
    }
    public long getTotal(string Key,string Enabled)
    {
        SqlParameter[] p = new SqlParameter[2];        
        p[0] = new SqlParameter("@Key", "%" + Key + "%");
        p[1] = new SqlParameter("@Enabled", Enabled); 
        return _DB.getTotalTable(_TableName+"_getTotal",p);
    }
    public DataTable getRecord(string ID, string Enabled)
    {
        SqlParameter[] p = new SqlParameter[4];
        p[0] = new SqlParameter("@TableName", _TableName);
        p[1] = new SqlParameter("@IDCol", _IDCol);
        p[2] = new SqlParameter("@IDValue", ID);
        p[3] = new SqlParameter("@Enabled", Enabled);
        return _DB.getDataTable("bz_getRecord" + _IDType, p);
    } 
    public int deleteRecord(string[] ID)
    {
        int count = 0;
        foreach (string str in ID)
        {
            SqlParameter[] p = new SqlParameter[4];
            p[0] = new SqlParameter("@TableName", _TableName);
            p[1] = new SqlParameter("@TableChild", _TableChild);
            p[2] = new SqlParameter("@IDCol", _IDCol);
            p[3] = new SqlParameter("@IDValue", str);
            count += _DB.updateData("bz_deleteRecord" + _IDType, p);
        }
        return count;
    }
    public int activeRecord(string[] ID, string Enabled)
    {
        int count = 0;
        foreach (string str in ID)
        {
            SqlParameter[] p = new SqlParameter[4];
            p[0] = new SqlParameter("@TableName", _TableName);
            p[1] = new SqlParameter("@IDCol", _IDCol);
            p[2] = new SqlParameter("@IDValue", str);
            p[3] = new SqlParameter("@Enabled", Enabled);
            count += _DB.updateData("bz_activeRecord" + _IDType, p);
        }
        return count;
    }

    public int insertRecord(string NameFull, string DepartmentVN, string DepartmentEN,string NickName, string Enabled)
    {
        SqlParameter[] p = new SqlParameter[5];
        p[0] = new SqlParameter("@NameFull", NameFull);
        p[1] = new SqlParameter("@DepartmentVN", DepartmentVN);
        p[2] = new SqlParameter("@DepartmentEN", DepartmentEN);
        p[3] = new SqlParameter("@NickName", NickName);
        p[4] = new SqlParameter("@Enabled", Enabled);
       
        return _DB.updateData(_TableName+"_insert",p);
    }
    public int updateRecord(string ID,string NameFull, string DepartmentVN, string DepartmentEN, string NickName, string Enabled)
    {
        SqlParameter[] p = new SqlParameter[6];
        p[0] = new SqlParameter("@ID", ID);
        p[1] = new SqlParameter("@NameFull", NameFull);
        p[2] = new SqlParameter("@DepartmentVN", DepartmentVN);
        p[3] = new SqlParameter("@DepartmentEN", DepartmentEN);
        p[4] = new SqlParameter("@NickName", NickName);
        p[5] = new SqlParameter("@Enabled", Enabled);
      
        return _DB.updateData(_TableName + "_update", p);
    }
}
